Normalization all indicators so that December 2019 = 100
vectors$REF_DATE = as.Date(vectors$REF_DATE)
head(vectors)
vector_names[1]
[1] "v65201210"
length(vector_names)
[1] 16
indicators1 <- vector(length=16)
for (i in 1:length(vector_names)) {
#print(i)
indicator = filter(vectors, VECTOR == vector_names[i])
ref_value = indicator$VALUE[indicator$REF_DATE == as.Date('2019-12-01')]
indicator$VALUE_INDEX = 100. * indicator$VALUE/ref_value
if (i == 1) {indicators = indicator}
else {indicators <- rbind(indicators, indicator)}
# indicators1[i] <- indicator
}
head(indicators)
indicators$descr <- sapply(indicators$VECTOR, function(x) {
vector_descr[x][[1]]
})
p <- ggplot(indicators, aes(x=REF_DATE, y=VALUE_INDEX)) + geom_line((aes(group=descr, color=descr))) +
scale_x_date(date_breaks="2 month", date_labels="%b %Y", limits = as.Date(c('2019-01-01','2020-06-01'))) + scale_y_continuous(breaks=seq(0, 180,20), limits= c(0, 180)) + labs(title='Index, December 2019=100', x='', y='')
ggplotly(p)
retail_sales_plot = ggplot() + geom_line(data=retail_sales_can, aes(x=REF_DATE, y=VALUE_INDEX, color='green'))
hours_worked_plot = geom_line(data=hours_worked_industries, aes(x=REF_DATE, y=VALUE_INDEX, color='blue'))
plot = retail_sales_plot + hours_worked_plot + scale_x_date(date_breaks="2 month", date_labels="%b %Y", limits = as.Date(c('2019-01-01','2020-06-01'))) + scale_y_continuous(breaks=seq(70, 105,5), limits= c(70, 105)) + scale_color_manual(labels = c("Retail trade sales (dollars)", "Actual hours worked"), values = c("blue", "red")) + labs(color='Legend')
plot
#ggplotly(plot)
< -
#select(hours_worked_plot, c("VALUES"))
hours_worked_industries %>% select(REF_DATE, VALUE_INDEX)
ggplot() + geom_line(data=hours_worked_industries, aes(x=REF_DATE, y=VALUE_INDEX))
Comments
I expect this date to be before the start of all time series/vectors.
Retrieve all vectors. They are concatunated along axis 0.